/**
 * 
 */
package com.objectdraw.server.tools;

import com.objectdraw.server.ObjectDrawServer;
import com.objectdraw.server.data.Action;
import com.objectdraw.server.tools.data.DrawingObject;

/**
 * Used to create server-side oval objects.
 * 
 * @author Harrison
 *
 */
public class OvalServerTool extends ServerTool {
	private DrawingObject dro = new DrawingObject();
	
	/**
	 * Initailize the tool
	 */
	public OvalServerTool(){
		super();
		name = "oval";
		dro.setColor(ObjectDrawServer.getInstance().getCurrentColor());
		dro.setTool(name);
	}
	
	/* (non-Javadoc)
	 * @see com.objectdraw.server.tools.ServerTool#addAction(com.objectdraw.server.data.Action)
	 */
	/**
	 * creates a new drawing object with the name: "oval" and the coords provided in the action
	 */
	@Override
	public void addAction(Action act) {
		if(act != null){
			if("mouse".equalsIgnoreCase(act.getAction())){
				if("released".equalsIgnoreCase(act.getEvent())){
					String[] cords = act.getArguments().split(" ");
					dro.AddCoords(cords[0], cords[1]);
					
					ObjectDrawServer serv = ObjectDrawServer.getInstance();
					serv.addObject(dro);

					dro.setColor(serv.getCurrentColor());
					dro.setTool(name);
					dro = new DrawingObject();
				}else if("pressed".equalsIgnoreCase(act.getEvent())){
					String[] cords = act.getArguments().split(" ");
					dro.AddCoords(cords[0], cords[1]);
				}
			}
		}
	}

}
